
import 'package:fijkplayer/fijkplayer.dart';
import 'package:flutter/material.dart';
import 'package:syn_4s/core/extension/int_extension.dart';
import 'package:syn_4s/core/model/cctv_camera_model.dart';
import '../shared/app_theme.dart';


class SurveillanceItem extends StatefulWidget {

  final CCTVModel cctvModel;

  SurveillanceItem(this.cctvModel);

  @override
  State<SurveillanceItem> createState() => _SurveillanceItemState();
}

class _SurveillanceItemState extends State<SurveillanceItem> {
  final FijkPlayer player = FijkPlayer();

  @override
  void initState() {
    super.initState();
    player.setDataSource(
        // "http://synergos.ddnsking.com:8000/SynCameraSvr/306F0B80.live.flv",
        "${widget.cctvModel.flvUrl}",
        autoPlay: true);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 190.px,
      color: Colors.white,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          FijkView(
            width: double.infinity,
            height: 160.px,
            player: player,
            fit: FijkFit.fill,
          ),
          Expanded(
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 6.px),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Flexible(
                        fit: FlexFit.tight,
                        flex: 1,
                        child: setText("${widget.cctvModel.name}", color: Colors.black, size: 14.px, fontWeight: FontWeight.w900)
                    ),
                    Flexible(
                        fit: FlexFit.tight,
                        flex: 1,
                        child: setText("${widget.cctvModel.createdAt}", color: Colors.black, size: 14.px)
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: [
                        buildOval()
                      ],
                    )
                  ],
                ),
              )
          )
        ],
      ),
    );
  }

  Widget buildOval() {
    return Container(
      height: 10.px,
      width: 10.px,
      decoration: BoxDecoration(
          color: Colors.green,
          borderRadius: BorderRadius.all(Radius.circular(6.px))),
    );
  }

  Widget setText(String text,{double? size, FontWeight? fontWeight, Color color = AppTheme.textColor}){
    return Text(
      text,
      style: TextStyle(
          fontSize: size,
          fontWeight: fontWeight,
          color: color
      ),
      overflow: TextOverflow.ellipsis,
      maxLines: 1,
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    player.release();
  }
}

